package com.gjty.healthmgr.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.gjty.healthmgr.bean.Page;
import com.gjty.healthmgr.bean.User;
import com.gjty.healthmgr.service.UserService;
import com.roc.dubbo.config.spring.annotation.InterfaceMethods;
import com.roc.dubbo.config.spring.annotation.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {

    private Logger logger = LoggerFactory.getLogger(UserController.class);
    @Reference(version = "1.0", check = false)
    @InterfaceMethods(methods = {@Method(name = "addUser", retries = 0, timeout = 3000)})
    private UserService userService;

    @ResponseBody
    @GetMapping("/queryUserPage")
    public Page<User> queryUserPage() {
        logger.info("consumer call queryUserPage");
        return userService.queryUserPage();
    }

    @GetMapping("/addUser")
    public String addUser() {
        logger.info("consumer call addUser");
        userService.addUser(new User());
        return "index";
    }
}
